import logging
from pyramid.view import view_config
from bbkb.KnowledgeBase import KnowledgeBase as kb

log = logging.getLogger(__name__)

@view_config(route_name='debugkb_loadtable_view', renderer='json')
def load_table_data(request):
    """Loads data for requested lookup table"""
    tablename = request.params['tablename']
    tabledata = kb.lookup_tables[tablename]
    ids = sorted(tabledata, key=lambda x: -tabledata[x]['frequency'])
    data = []
    for id in ids:
        data.append({'id':id,'value':tabledata[id]})
    return {'data':data}
    
